//
//  HomeContentCell.m
//  万物记
//
//  Created by Ajen on 2019/6/16.
//  Copyright © 2019 Ajen. All rights reserved.
//

#import "HomeContentCell.h"
#import "ACLabel.h"

#define RIGHT_LINE_WIDTH 5

#define kHexCharsArr @[@"#",@"0",@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"a",@"A",@"b",@"B",@"c",@"C",@"d",@"D",@"e",@"E",@"f",@"F"]

@implementation HomeContentCell{
    UILabel * nameLabel;
    UILabel * contentLabel;
    UIView * rightLine_0;
    UIView * rightLine_1;
    UIView * rightLine_2;
    NSArray<UIView*> * rightLineArr;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
}

-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self=[super initWithStyle:style reuseIdentifier:reuseIdentifier]){
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        nameLabel = [UILabel new];
        nameLabel.aj_Text(@"万物记").aj_textColorHexStr(@"#2d2e36").aj_addToView(self);
        nameLabel.font = [UIFont systemFontOfSize:15 weight:UIFontWeightMedium];
        [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).offset(20);
            make.top.equalTo(self).offset(16);
            make.right.equalTo(self).offset(-25);
            make.height.equalTo(@16);
        }];
        
        contentLabel = [ACLabel new];
        contentLabel.aj_Text(@"万物记万物记万物记万物记万物记万物记万物记万物记万物记万物记万物记万物记万物记万物记万物记万物记万物记万物记万物记万物记万物记万物记万物记").aj_textColorHexStr(@"#2d2e36").aj_numberOfLines(0).aj_addToView(self);
        contentLabel.font = [UIFont systemFontOfSize:13 weight:UIFontWeightThin];
        [contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).offset(20);
            make.top.equalTo(nameLabel.mas_bottom).offset(5);
            make.right.equalTo(self).offset(-25);
            make.bottom.equalTo(self).offset(-16);
        }];
        
        UIView * bottomLine = [UIView new];
        bottomLine.aj_bgColorHexStr(@"#7a7374").aj_addToView(self);
        bottomLine.alpha = 0.3;
        [bottomLine mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.bottom.right.equalTo(self);
            make.height.equalTo(@0.5);
        }];
        
        rightLine_0 = [UIView new];
        rightLine_0.backgroundColor = [UIColor whiteColor];
        [self addSubview:rightLine_0];
        [rightLine_0 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.bottom.equalTo(self);
            make.right.equalTo(self);
            make.width.equalTo(@(RIGHT_LINE_WIDTH));
        }];
        rightLine_1 = [UIView new];
        rightLine_1.backgroundColor = [UIColor whiteColor];
        [self addSubview:rightLine_1];
        [rightLine_1 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.bottom.equalTo(self);
            make.right.equalTo(rightLine_0.mas_left);
            make.width.equalTo(@(RIGHT_LINE_WIDTH));
        }];
        rightLine_2 = [UIView new];
        rightLine_2.backgroundColor = [UIColor whiteColor];
        [self addSubview:rightLine_2];
        [rightLine_2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.bottom.equalTo(self);
            make.right.equalTo(rightLine_1.mas_left);
            make.width.equalTo(@(RIGHT_LINE_WIDTH));
        }];
        rightLineArr = @[rightLine_0,rightLine_1,rightLine_2];
        
//        [self displayTest];
        
    }
    return self;
}

-(void)setItemModel:(LocalJsonModelContentslist *)itemModel{
    _itemModel = itemModel;
    
    nameLabel.text = _itemModel.title;
    contentLabel.text = _itemModel.content;
    rightLineArr[0].backgroundColor = [UIColor whiteColor];
    rightLineArr[1].backgroundColor = [UIColor whiteColor];
    rightLineArr[2].backgroundColor = [UIColor whiteColor];
    for(int i = 0 ; i < _itemModel.colorsHex.count ; i++){
        if(_itemModel.colorsHex[i].length == 7){
            BOOL is16 = YES;
            for(int j = 0 ; j < 7 ; j++){
                if(![kHexCharsArr containsObject:[_itemModel.colorsHex[i] substringWithRange:NSMakeRange(j, 1)]]){//16进制字符数组不包含这个字符
                    is16 = NO;
                }
            }
            if(is16){
                rightLineArr[i].backgroundColor = [UIColor colorWithAjenHexString:_itemModel.colorsHex[i]];
            }else{
                [rightLineArr[i] mas_updateConstraints:^(MASConstraintMaker *make) {
                    make.width.equalTo(@(CGFLOAT_MIN));
                }];
            }
        }
    }
}



-(void)setTitleString:(NSString *)titleString{
    _titleString = titleString;
    nameLabel.text = _titleString;
}

@end
